package com.dropdb.demo.controller.wx;

import com.dropdb.demo.bean.Feedback;
import com.dropdb.demo.bean.User;
import com.dropdb.demo.bean.enumeration.ErrorReason;
import com.dropdb.demo.bean.vo.BaseRespVO;
import com.dropdb.demo.service.FeedbackService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx/feedback")
public class WxFeedbackController {
    @Autowired
    FeedbackService feedbackService;

    @RequestMapping("submit")
    public BaseRespVO submitFeedback(@RequestBody Feedback feedback) {
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        if (user == null) return BaseRespVO.error(ErrorReason.UN_LOGIN.getCode(),ErrorReason.UN_LOGIN.getReason());
        Integer result = feedbackService.submitFeedback(feedback, user.getId(), user.getUsername());
        if (!result.equals(1)) return BaseRespVO.error(504, "添加失败");
        return BaseRespVO.ok();
    }
}
